package zozopo.oa;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.comm.ZOZOPOCODE;
import zozopo.operations.oa.OutlayOS;
import zozopo.operations.oa.OutlayTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.PurchaseOS;
import zozopo.warehouse.operations.PurchaseTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class CancelOutlayAction extends ActionSupport implements Action,SessionAware{
	//传入参数
	private int id;
	
	
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		//权限处理
		UserTB user = (UserTB) session.get("userInfo");
		if(user == null){
			return NONE;
		}
	
		
		OutlayOS outlayOS = new OutlayOS();
		
		OutlayTB outlay = outlayOS.getOutlayById(id);
		
		String state = outlay.getState_outlay();
		
		if(!state.equals(ZOZOPOCODE.NORMAL)){
			//不是默认状态不能取稍.
			outlayOS.releaseConnection();
			return ERROR;
		}
		
		if(!user.getUser_email().equals(outlay.getUseremail_outlay())){
			outlayOS.releaseConnection();
			return ERROR;
		}
		
		
		
		if(!outlayOS.cancel(id)){
			return ERROR;
		}
		
		
		outlayOS.releaseConnection();
		
		return SUCCESS;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

}
